package org.algorithm.biubiu.wheel_1.数组.二月;

import java.util.ArrayList;
import java.util.List;

/**
 * @author biubiu
 * @version 1.0
 * @date 2022/03/06 9:38 PM  周三题目
 * @description: 前缀和
 *
 * security = [5,3,3,3,5,6,2], time = 2
 *
 * 参考题解： https://leetcode-cn.com/problems/find-good-days-to-rob-the-bank/solution/gong-shui-san-xie-qian-zhui-he-yun-yong-gf604/
 * uri： https://leetcode-cn.com/problems/find-good-days-to-rob-the-bank/
 */
public class 适合打劫银行的日子 {

    public static void main(String[] args) {
        int[] nums = {5,3,3,3,5,6,2};
        System.out.println(goodDaysToRobBank(nums, 2));
    }


    public static List<Integer> goodDaysToRobBank(int[] security, int time) {
        List<Integer> ans = new ArrayList<>();
        int len = security.length;
        int[] tmp = new int[len];
        for(int i=1;i<len;i++){
            if(security[i]==security[i-1]) continue;
            tmp[i] = security[i] > security[i-1]? 1:-1;
        }
        int[] a = new int[len+1], b = new int[len+1];

        for(int i=1;i<=len;i++){
            a[i] = a[i-1] + (tmp[i - 1] == 1 ? 1 : 0);
        }
        for(int i=1;i<=len;i++){
            b[i] = b[i-1] + (tmp[i - 1] == -1 ? 1 : 0);
        }

        for(int i = time;i<len-time;i++){
            int ar =a[i+1]-a[i+1-time];
            int br =b[i+1+time] - b[i+1];
            if(ar==0 && br ==0){
                ans.add(i);
            }
        }
        return ans;
    }
}
